package week04;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class Testing
{
        public static void main(String... args)
        {
                final DefaultTableModel model = new DefaultTableModel()
                {
                        @Override
                        public boolean isCellEditable(int row, int column)
                        {
                                return false;
                        }
                };

                model.addColumn("One");
                model.addColumn("Two");

                final JTable table = new JTable(model);
                JButton button = new JButton("Click to add data to the table");


               //get data in a vector from the list you are getting from the database
                final Vector<String> newRow = new Vector<String>();
                newRow.add("Value1");
                newRow.add("Value2");

                button.addActionListener(new ActionListener()
                {
                        public void actionPerformed(ActionEvent ae)
                        {
                                model.addRow(newRow);
                        }
                });


                JFrame frame = new JFrame("Testing");
                frame.getContentPane().add(button, BorderLayout.NORTH);
                frame.getContentPane().add(table, BorderLayout.CENTER);
                frame.setSize(400, 200);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
        }
}
